package ru.elifantiev.cityrouter.infrastructure.map;


import android.content.Context;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import android.widget.FrameLayout;
import ru.elifantiev.cityrouter.infrastructure.map.Yandex.YandexMapWrapper;

import java.util.HashMap;

public class MapFactory {

    private static HashMap<String, Integer> layoutMap;

    static {
        layoutMap = new HashMap<String, Integer>();
        layoutMap.put("Yandex", -1);
        layoutMap.put("Google", -1);
    }

    public static MapWrapper build(ViewCache viewCache, Context ctx, FrameLayout container) {
        String mapVariant = getProvider(ctx);
        int layoutId = layoutMap.get(mapVariant);

        if(layoutId == -1)
            throw new RuntimeException("No layout registered for implementation " + mapVariant);

        if (mapVariant.equals("Yandex"))
            return new YandexMapWrapper(viewCache, ctx, container, layoutId);

        throw new IllegalArgumentException(mapVariant + " is unknown map variant");
    }

    public static String getProvider(Context ctx) {
        return "Yandex";
    }

    public static void registerImplementationLayout(String implementation, int layoutId) {
        if(layoutMap.containsKey(implementation))
            layoutMap.put(implementation, layoutId);
        else
            throw new IndexOutOfBoundsException("No such implementation: " + implementation);
    }

}
